package com.lin.service.impl;

import com.lin.entity.News;
import com.lin.service.NewsService;
import com.lin.util.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Created by Lin Weihong
 * @date on 2022/4/14 20:36
 */
@Service
public class NewsServiceImpl implements NewsService {

    @Resource
    RedisUtil redisUtil;

    @Override
    public List<News> findHotNews() {
        Map<Object, Object> hotNewsMap = redisUtil.hmget("hotnews");
        News news = null;
        List<News> newsList = new ArrayList<>();
        for (Map.Entry<Object, Object> map : hotNewsMap.entrySet()) {
            news = new News();
            news.setTitle((String) map.getKey());
            news.setLink((String) map.getValue());
            newsList.add(news);
        }
        return newsList;
    }
}
